//
// Created by fazhehy on 2024/3/4.
//

#ifndef ST7789_H
#define ST7789_H

#include "hy_common_inc.h"
#include <stdarg.h>

#define ST7789_DC_PIN       P07_0
#define ST7789_RES_PIN      P07_5
#define ST7789_CS_PIN       P07_3
//#define ST7789_BLK_PIN

#define ST7789_WIDTH 240
#define ST7789_HEIGHT 280

#define ST7789_DC(x)                    ((x) ? (gpio_high(ST7789_DC_PIN))  : (gpio_low(ST7789_DC_PIN)))
#define ST7789_RST(x)                   ((x) ? (gpio_high(ST7789_RES_PIN)) : (gpio_low(ST7789_RES_PIN)))
#define ST7789_CS(x)                    ((x) ? (gpio_high(ST7789_CS_PIN))  : (gpio_low(ST7789_CS_PIN)))
//#define ST7789_BLK(x)                   ((x) ? (gpio_high(ST7789_BL_PIN))  : (gpio_low(ST7789_BL_PIN)))

#define ST7789_COLOR_WHITE       0xFFFF
#define ST7789_COLOR_BLACK       0x0000
#define ST7789_COLOR_BLUE        0x001F
#define ST7789_COLOR_RED         0xF800
#define ST7789_COLOR_MAGENTA     0xF81F
#define ST7789_COLOR_GREEN       0x07E0
#define ST7789_COLOR_CYAN        0x7FFF
#define ST7789_COLOR_YELLOW      0xFFE0
#define ST7789_COLOR_GRAY        0X8430
#define ST7789_COLOR_BRED        0XF81F
#define ST7789_COLOR_GRED        0XFFE0
#define ST7789_COLOR_GBLUE       0X07FF
#define ST7789_COLOR_BROWN       0XBC40
#define ST7789_COLOR_BRRED       0XFC07
#define ST7789_COLOR_DARKBLUE    0X01CF
#define ST7789_COLOR_LIGHTBLUE   0X7D7C
#define ST7789_COLOR_GRAYBLUE    0X5458
#define ST7789_COLOR_LIGHTGREEN  0X841F
#define ST7789_COLOR_LGRAY       0XC618
#define ST7789_COLOR_LGRAYBLUE   0XA651
#define ST7789_COLOR_LBBLUE      0X2B12

typedef struct {
    uint8_t * data;
    uint8_t width;
    uint8_t height;
}font_t;

typedef font_t * pFont;

extern pFont st7789_font_8x16;
extern pFont st7789_font_6x8;

#define ST7789_PEN_COLOR    ST7789_COLOR_RED
#define ST7789_BG_COLOR     ST7789_COLOR_WHITE

void st7789_init();
void st7789_clear();
void st7789_fill_color(uint16_t color);
void st7789_fill(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, uint16_t color);

void st7789_show_char(uint16_t x, uint16_t y, pFont font, char ch);
void st7789_show_string(uint16_t x, uint16_t y, const char *str);
uint8_t st7789_printf(uint16_t x, uint16_t y, const char * format, ...);

void st7789_draw_point(uint16_t x, uint16_t y, uint16_t color);
void st7789_draw_big_point(uint16_t x, uint16_t y, uint16_t color);
void st7789_draw_line(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1,uint16_t color);
void st7789_draw_vLine(uint16_t x, uint16_t y, uint16_t len, uint16_t color);
void st7789_draw_hLine(uint16_t x, uint16_t y, uint16_t len, uint16_t color);
void st7789_draw_rectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
void st7789_draw_filled_rectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
void st7789_draw_circle(uint16_t x0, uint16_t y0, uint8_t r, uint16_t color);
void st7789_draw_filled_circle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);
void st7789_draw_round_rectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t color);
void st7789_draw_filled_round_rectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t color);



#endif //ST7789_H
